In [ ]:
import menpo.io as pio

Load and plot an image:


In [ ]:
%matplotlib inline
breaking_bad = pio.import_builtin_asset('breakingbad.jpg')
breaking_bad.crop_to_landmarks(boundary=20)
breaking_bad.constrain_mask_to_landmarks()
breaking_bad.view(masked=False)
print breaking_bad.mask

Also visualize the landmarks:


In [ ]:
breaking_bad.landmarks.view()

Otherwise, visualize each channel separately:


In [ ]:
breaking_bad.view(channels='all')

1 HOG Features

The HOG (Histogram of Oriented Gradients) descriptors method clusters gradient orientations in different bins for localized sub-windows of the input image, resulting in counting occurences of the orientations.

1.1 Dense HOGs

This is an example of dense HOG (step of 3 pixels horizontally and vertically). It also includes all possible parameters.


In [ ]:
%%time
hog = breaking_bad.features.hog(mode='dense',
                                algorithm='dalaltriggs',
                                cell_size=8,
                                block_size=2,
                                num_bins=9,
                                signed_gradient=True,
                                l2_norm_clip=0.2,
                                window_height=1, window_width=1, window_unit='blocks',
                                window_step_vertical=3, window_step_horizontal=3, window_step_unit='pixels',
                                padding=True,
                                verbose=True,
                                constrain_landmarks=True)

Visualize with and without mandmarks and either in glyph or image mode:


In [ ]:
hog.view(masked=False)

In [ ]:
hog.glyph().landmarks.view()

or a visualization that I really like:


In [ ]:
hog.glyph(vectors_block_size=1,).landmarks.view(channels='all')

1.2 Sparse HOGs

Setting mode to sparse returns the traditional sparsely-sampled HOGs:


In [ ]:
%%time
hog = breaking_bad.features.hog(mode='sparse',
                                algorithm='zhuramanan',
                                verbose=True)
hog.glyph(vectors_block_size=4).view()

and with landmarks:


In [ ]:
hog.landmarks.view(masked=False)

1.3 Default Options

The default HOG options:


In [ ]:
%%time
hog = breaking_bad.features.hog()

are the most dense and of course slowest...


In [ ]:
print hog

They return a HOG image with the same width and height as the input image.


In [ ]:
hog.view(channels=range(9))

In [ ]:
hog.glyph(vectors_block_size=1).landmarks.view(channels='all')

1.4 Constrain Landmarks

In some cases, depending on the options given by the user, the landmarks may end up outside of the bounds of the features image. By enabling the flag constrain_landmarks, the landmarks that lie outside the borders will be constrained to the image bounds. The default value is constrain_landmarks=True. For example:


In [ ]:
# clipping disabled
subplot(121); title('Clipping disabled')
breaking_bad.resize([150, 150]).features.hog(mode='sparse',constrain_landmarks=False).landmarks.view(channels=1,masked=False)
# clipping enabled
subplot(122); title('Clipping enabled')
breaking_bad.resize([150, 150]).features.hog(mode='sparse').landmarks.view(channels=1,masked=False)

1.4 Windows Centres

The HOGs always return a matrix with the coordinates of the windows centers on which they were computed:


In [ ]:
hog = breaking_bad.features.hog(mode='sparse')
print hog.pixels.shape
print hog.window_centres.shape

2 IGO Features

2.1 Single angles

Example of such computation. This is the default:


In [ ]:
%%time
igo_single = breaking_bad.features.igo()

In [ ]:
print igo_single

In [ ]:
igo_single.view(channels='all')

or


In [ ]:
igo_single.glyph().view(channels='all')

2.2 Double angles


In [ ]:
%%time
igo = breaking_bad.features.igo(double_angles=True, verbose=True)

In [ ]:
igo.view(channels='all')

In [ ]:
igo.glyph(vectors_block_size=1).landmarks.view(channels='all')